package com.smh.a02IOStreamDemo2;

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class CharSetDemo3 {
    public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {

        //编码(utf-8)
        String str = "草泥马";
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));

        //GBK
        String str2 = "草泥马";
        byte[] bytes2 = str.getBytes("GBK");
        System.out.println(Arrays.toString(bytes2));

        //解码(utf-8)
        String s = new String(bytes);
        System.out.println(s);

        String s1 = new String(bytes2);
        System.out.println(s1);
        //  GBK
        String s2 = new String(bytes, "GBK");
        System.out.println(s2);

        String s3 = new String(bytes2, "GBK");
        System.out.println(s3);
    }
}
